package com.group.eams.controller;






import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.group.eams.pojo.dto.AssetStorageQueryDto;
import com.group.eams.pojo.dto.FixedAssetDetailQueryDto;
import com.group.eams.pojo.entity.AssetStorage;
import com.group.eams.pojo.entity.AssetStorage;
import com.group.eams.pojo.entity.AssetStorage;
import com.group.eams.pojo.vo.AssetStorageListVo;
import com.group.eams.pojo.vo.FixedAssetDetailListVo;
import com.group.eams.service.AssetStorageService;
import com.group.pojo.dto.BatchDeleteDto;
import com.group.result.Result;
import com.group.result.ResultEnum;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 资产入库表(AssetStorage)表控制层
 *
 * @author 
 * @since 2024-10-30 12:58:28
 */
@RestController
@RequestMapping("/assetStorage")
//@ResponseBody
public class AssetStorageController  {
    /**
     * 服务对象
     */
    @Autowired
    private AssetStorageService assetStorageService;


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    @ApiOperation(value = "资产入库列表")
    public Result List(AssetStorageQueryDto assetStorageQueryDto){
        Page<AssetStorage> page = new Page<>(assetStorageQueryDto.getPage(), assetStorageQueryDto.getLimit());

        Page<AssetStorageListVo> listVoPage = assetStorageService.findAssetStorageList(page, assetStorageQueryDto);

        return Result.buildSuccess(listVoPage.getTotal(), listVoPage.getRecords());
    }

    @RequestMapping(value = "/find",method = RequestMethod.GET)
    @ApiOperation(value = "根据id查询资产入库信息")
    public Result find(@RequestParam Long id){
        AssetStorage assetStorage = assetStorageService.getById(id);
        return Result.buildSuccess(assetStorage);
    }

    @RequestMapping(value = "/add",method = RequestMethod.POST)
    @ApiOperation(value = "添加资产入库信息")
    public Result add(@RequestBody AssetStorage assetStorage){
        boolean result = assetStorageService.save(assetStorage);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/update",method = RequestMethod.POST)
    @ApiOperation(value = "修改资产入库信息")
    public Result update(@RequestBody AssetStorage assetStorage){
        boolean result = assetStorageService.updateById(assetStorage);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/delete",method = RequestMethod.GET)
    @ApiOperation(value = "删除资产入库信息")
    public Result add(@RequestParam Long id){
        boolean result = assetStorageService.removeById(id);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }
    @RequestMapping(value = "/findAll",method = RequestMethod.GET)
    @ApiOperation(value = "查询所有资产入库信息")
    public Result findAll(){
        List<AssetStorage> assetStorageList = assetStorageService.list();
        return Result.buildSuccess(assetStorageList);
    }

    @RequestMapping(value = "/batchRemove",method = RequestMethod.POST)
    @ApiOperation(value = "批量删除资产入库信息")
    public Result batchRemove(@RequestBody BatchDeleteDto batchDeleteDto){
        boolean result = assetStorageService.removeByIds(batchDeleteDto.getIds());
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/findByApplicationNum",method = RequestMethod.GET)
    @ApiOperation(value = "根据申请编号查询资产借用信息")
    public Result findByApplicationNum(@RequestParam String applicationNum){
        AssetStorage assetStorage = assetStorageService.findByApplicationNum(applicationNum);
        return Result.buildSuccess(assetStorage);
    }

    @RequestMapping(value = "/assetDetail",method = RequestMethod.GET)
    @ApiOperation(value = "资产借用明细")
    public Result assetList(FixedAssetDetailQueryDto fixedAssetDetailQueryDto){
        Page<FixedAssetDetailListVo> page = new Page<>(fixedAssetDetailQueryDto.getPage(), fixedAssetDetailQueryDto.getLimit());
        Page<FixedAssetDetailListVo> listVoPage = assetStorageService.findByQueryDto(page, fixedAssetDetailQueryDto);
        return Result.buildSuccess(listVoPage.getTotal(), listVoPage.getRecords());
    }




    @RequestMapping(value = "/addBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量添加资产入库信息")
    public Result addBatch(@RequestBody List<AssetStorage> assetStorageList){
        boolean result = assetStorageService.saveBatch(assetStorageList);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    @RequestMapping(value = "/updateBatch",method = RequestMethod.POST)
    @ApiOperation(value = "批量修改资产入库信息")
    public Result updateBatch(@RequestBody List<AssetStorage> assetStorageList){
        boolean result = assetStorageService.updateBatchById(assetStorageList);
        return result?Result.buildSuccess():Result.buildFail(ResultEnum.OPTION_FAIL);
    }

    
}

